#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#
# /*
#  *  Copyright 2021
#  *
#  *  This program is free software: you can redistribute it and/or modify
#  *  it under the terms of the GNU General Public License as published by
#  *  the Free Software Foundation, either version 3 of the License, or
#  *  (at your option) any later version.
#  *
#  *  This program is distributed in the hope that it will be useful,
#  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  *  GNU General Public License for more details.
#  *
#  *  You should have received a copy of the GNU General Public License
#  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  *
#  * SPDX-License-Identifier: GPL-3.0+
#  * License-Filename: LICENSE
#  *
#  */
#
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# Macro: AC_INIT (package, version, [bug-report], [tarname], [url])
# minor version number is increased at important feature change
# Process with autogen.sh or manual:
# aclocal
# autoheader
# autoconf
# libtoolize --force --automake
# automake -a --gnu --include-deps
# or do this all using autoreconf -fvim
#
# test also using scan-build from llvm clang tools
#

AC_PREREQ([2.69])
AC_INIT([packgpl], [0.4], [unknown])
AC_CONFIG_SRCDIR([src/load.h])
AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

AC_LANG(C)

# Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_MAKE_SET

# Use c99 mode
CFLAGS="$CFLAGS -g -std=c99 -Wall -Wextra -pedantic "
AC_MSG_RESULT($CFLAGS)

# Checks for libraries.
# -lgc is boehm garbage collector for memory allocations
AC_CHECK_LIB([gc], [GC_INIT])

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_OFF_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_CHECK_FUNCS([strchr strdup strerror strtol])

# compilation date in config.h
# CONFIG_DATE=`date +"%a %x %Y"`
CONFIG_DATE=`date +"%a %d %b %Y"`

AC_SUBST(CONFIG_DATE)

AC_DEFINE_UNQUOTED(COMPILE_DATE, ["$CONFIG_DATE"], [Year, month and day this program is compiled.])

# short system name in config.h
CONFIG_UNAME=`uname -s`

AC_SUBST(CONFIG_UNAME)

AC_DEFINE_UNQUOTED(COMPILE_UNAME, ["$CONFIG_UNAME"], [System where this is compiled.])

# final compiler settings
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(WARNING_CFLAGS)

AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

AC_MSG_NOTICE([

Configuration:
  Source code location	${srcdir}
  Build code location	${builddir}
  Destination prefix	${prefix}
  C-Compiler		${CC}
  Config CFLAGS		"${CFLAGS}"
  Config LIBS		"${LIBS}"
  Config PACKAGE_CFLAGS	"$PACKAGE_CFLAGS"
  Config COMPILE_DATE	"$CONFIG_DATE"
  Config COMPILE_UNAME	"$CONFIG_UNAME"
])

# end.
